import IPairTxData from '~/models/IData'
import IPlugin from './IPlugin'
// import { parseWETHtoETH } from '~/util'


export default class SwapNamePlugin implements IPlugin {

    public name: string =  'SwapName'

    async modData(data: IPairTxData) {
        if (data.mints.length == 0) {
            console.warn('Pair does not have any liquidity. Abort!')
            return data
        }
        const pair = data.mints[0].pair
        const token0 = pair.token0.symbol
        const token1 = pair.token1.symbol

        const mints = data.mints
        const burns = data.burns
        const swaps = data.swaps

        for (let i = 0; i < mints.length; i++) {
            mints[i].swapName = `add ${token0} and ${token1}`
        }
        for (let i = 0; i < burns.length; i++) {
            burns[i].swapName = `remove ${token0} and ${token1}`
        }
        for (let i = 0; i < swaps.length; i++) {
            if (parseFloat(swaps[i].amount0In) > 0 && parseFloat(swaps[i].amount1In) == 0) {
                swaps[i].swapName = `swap ${token0} for ${token1}`
            }
            else if (parseFloat(swaps[i].amount1In) > 0 && parseFloat(swaps[i].amount0In) == 0) {
                swaps[i].swapName = `swap ${token1} for ${token0}`
            }
        }
        return data
    }
}
